package com.mlethe.android.demo.plane;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Scroller;

import androidx.annotation.Nullable;

/**
 * 飞机座位图
 */
public class PlaneSeatView extends View {

    /**
     * 中间过道宽度
     */
    private int corridorSize = 20;
    /**
     * vip座椅间空隙
     */
    private int vipSpace = 10;
    /**
     * 普通座椅间空隙
     */
    private int seatSpace = 8;
    /**
     * 行数宽度
     */
    private int rowsWidth = 100;
    /**
     * vip座椅资源id，普通座椅资源id
     */
    private int vipSeatResId, seatResId;
    /**
     * vip座椅图片，普通座椅图片
     */
    private Bitmap vipSeat, seat;
    /**
     * vip座椅大小，普通座椅大小
     */
    private int vipSeatSize, seatSize;

    private Matrix matrix;

    private Scroller mScroller;

    private int mScreeHeight;//屏幕高度
    private int mLastY;
    private int mStart;
    private int mEnd;
    private Paint mPaint;

    public PlaneSeatView(Context context) {
        this(context, null);
    }

    public PlaneSeatView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PlaneSeatView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        //DisplayMetrics 类提供了一种关于显示的通用信息，如显示大小，分辨率和字体。
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        mScreeHeight = dm.heightPixels;//高度（像素）
        mScroller = new Scroller(context);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.YELLOW);
        mPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        setMeasuredDimension(width, 3000);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getWidth();
        LinearGradient lg = new LinearGradient(0,0,width,3000,Color.RED,Color.BLUE, Shader.TileMode.MIRROR);
        mPaint.setShader(lg);
        canvas.drawRect(0, 0, width, 3000, mPaint);
    }

}
